<template>
  <a-modal
          :title="title"
          :width="1200"
          :visible="visible"
          :confirmLoading="confirmLoading"
          :destroyOnClose="true"
          @cancel="handleCancel"
          cancelText="关闭"
  >
  <a-card :bordered="false">
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="12">
          <a-col :md="6" :sm="8">
            <a-form-item
              label="编号"
              :maxLength="50">
              <a-input placeholder="请输入编号" v-model="queryParam.tmplCode"></a-input>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="8">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button
                @click="() => {this.$objToReset(queryParam),$refs.tables.refresh(true)}"
                icon="reload"
                style="margin-left: 8px">重置</a-button>
            </span>
          </a-col>
        </a-row>
      </a-form>
      <div class="table-operator">
        <a-button @click="$refs.modalEdit.add(subItem)" type="primary" icon="plus" >添加</a-button>
        <a-dropdown v-if="selectedRowKeys.length > 0">
          <a-menu slot="overlay">
            <a-menu-item>
              <a-popconfirm
                  title="确定删除吗?"
                  @confirm="() => handleDelete()"
                  v-wx-role="20904">
                <a><a-icon type="delete"/>删除</a>
              </a-popconfirm>
            </a-menu-item>
          </a-menu>
          <a-button style="margin-left: 8px">批量操作<a-icon type="down"/></a-button>
        </a-dropdown>
      </div>
      <s-table
        ref="tables"
        rowKey="id"
        size="middle"
        :scroll="{ x: 1100 }"
        :columns="columns"
        :alert="options.alert"
        :data="loadData">
        <template slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)" >
            <a-icon type="edit"/>编辑</a>
         <!-- <a-divider type="vertical"/>
          <a @click="handelView(record)" v-wx-role="20904"><a-icon/> 查看</a>-->
          <a-divider type="vertical"/>
          <a-popconfirm title="确定删除吗?" @confirm="() =>handleDelete(record.id)" v-wx-role="20903">
            <a>删除</a>
          </a-popconfirm>
        </template>
      </s-table>

      <health-sub-item-rst-tmpl-edit ref="modalEdit" @ok="modalEditOk"></health-sub-item-rst-tmpl-edit>
      <health-sub-item-rst-tmpl-view ref="modalView"></health-sub-item-rst-tmpl-view>
    </div>
  </a-card>
    <template slot="footer">
      <a-button @click="handleCancel" style="margin-right: .8rem">关闭</a-button>
    </template>
  </a-modal>

</template>

<script>
  import { STable, Ellipsis } from '@/components'
  import { deleteAction, postAction } from '@/api/manage'
  import { mixin } from '@/utils/mixin'
  import HealthSubItemRstTmplEdit from './HealthSubItemRstTmplEdit'
  import HealthSubItemRstTmplView from './HealthSubItemRstTmplView'

  export default {
    name: 'HealthSubItemRstTmplListWin',
    mixins: [mixin],
    components: { STable, Ellipsis, HealthSubItemRstTmplEdit, HealthSubItemRstTmplView },
    data () {
      return {
          title:'',
        visible: false,
          confirmLoading:false,
        // 查询条件
        queryParam: {
          title: ''
        },
        // 表头
        // 如果需要字典，那么需要在columns列中加入 customRender: (text) => this.$sysDictFilter(text, 'xxxx')xxxx 为dataIndex
        columns: [
          {
            title: '模板编号',
            dataIndex: 'tmplCode'
          },
          {
            title: '报告项目',
            dataIndex: 'subItemName'
          },
          {
            title: '所见',
            dataIndex: 'finding'
          },
          {
            title: '小结',
            dataIndex: 'summary'
          },
          {
            title: '是否异常',
            dataIndex: 'isAbnormal',
              customRender: (text) => this.$sysDictFilter(text, 'whetherFlag')
          },
            {
                title: '是否默认选项',
                dataIndex: 'isDefault',
                customRender: (text) => this.$sysDictFilter(text, 'whetherFlag')
            },{
                title: '是否排除其他异常',
                dataIndex: 'isUnique',
                customRender: (text) => this.$sysDictFilter(text, 'whetherFlag')
            },
          {
            title: '操作',
            dataIndex: 'action',
            align: 'center',
            fixed: 'right',
            scopedSlots: { customRender: 'action' }
          }
        ],
        // 加载数据方法 必须为 Promise 对象
        loadData: parameter => {
          console.log('loadData.parameter', parameter)
            this.queryParam.subItemId = this.subItem.id
          return postAction(this.url.list, Object.assign(parameter, this.queryParam))
              .then(res => {
                return res.result
              })
        },
        selectedRowKeys: [],
        options: {
          alert: {
            clear: () => {
              this.selectedRowKeys = []
            }
          },
          rowSelection: {
            selectedRowKeys: this.selectedRowKeys,
            onChange: this.onSelectChange,
            type: 'checkbox'
          }
        },
          subItem:undefined,
        url: {
          list: '/system/healthSubItemRstTmpl/list',
          delete: '/system/healthSubItemRstTmpl/delete'
        }
      }
    },
    computed: {},
    methods: {
        show(record){
            this.visible=true

            this.subItem = record
            // this.$refs.tables.refresh(true)

        },
      // 删除
      handleDelete (record) {
        if (!record) {
          // 如果没有传入，那么批量删除
          record = this.selectedRowKeys.join(',')
        }
        deleteAction(this.url.delete, { ids: record }).then((resp) => {
          this.$message.success('删除成功!')
          this.$refs.tables.refresh(true)
        })
      },
      // 用户编辑
      handleEdit (record) {
        this.$refs.modalEdit.edit(record)
      },
      searchQuery () {
        this.$refs.tables.refresh(true)
      },
      // 保存刷新
      modalEditOk () {
        this.$refs.tables.refresh()
      },
      // 查看
      handelView (record) {
        this.$refs.modalView.show(record)
      },
      //开启选择
      onSelectChange (selectedRowKeys) {
         console.log('selectedRowKeys changed: ', selectedRowKeys)
         this.selectedRowKeys = selectedRowKeys
      },
        // 关闭
        handleCancel () {
            this.close()
        },
        close () {
            // this.$refs.ruleForm.resetFields()
            this.subItem={}
            this.$objToReset(this.queryParam)
            this.$emit('close')
            this.visible = false
        },
    },
    watch: {}
  }
</script>
<style scoped>
</style>
